/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024.
 * Description: RTOS Process Context asm header
 * Create: 2024-07-13
 */
#ifndef __INTERNAL_RTPC_H
#define __INTERNAL_RTPC_H

#include <linux/printk.h>
#include <linux/bug.h>
#include <linux/jump_label.h>
#include <linux/task_struct_extend.h>
#include <linux/rtos_rtpc_rpc.h>

#define rpc_notice(fmt, args...) \
	pr_notice("[RPC KERNEL][NOTICE][%s][%d]: "fmt, __func__, __LINE__, ##args)

#define rpc_err(fmt, args...) \
	pr_err("[RPC KERNEL][ERROR][%s][%d]: "fmt, __func__, __LINE__, ##args)

#define rpc_alert(fmt, args...) \
	pr_alert("[RPC KERNEL][ALERT][%s][%d]: "fmt, __func__, __LINE__, ##args)

#define rpc_emerg(fmt, args...) \
	pr_emerg("[RPC KERNEL][EMERG][%s][%d]: "fmt, __func__, __LINE__, ##args)

DECLARE_STATIC_KEY_FALSE(sysctl_rpc_kernel_stats);

noinline __attribute__((cold)) void rtpc_stat_call(void);
noinline __attribute__((cold)) void rtpc_stat_fixup(size_t reason);

/*
 * This func should be called by self(tsk == current)
 * When tsk != current, we should use READ_ONCE()
 */
static inline struct rpc_service_info *rpc_get_service_info_self(struct task_struct *tsk)
{
	struct rtos_task_struct *rtos_task = task_to_rtos_task(tsk);

#ifdef CONFIG_RTOS_RTPC_RPC_DEBUG_BUILD
	BUG_ON(tsk != current);
#endif

	return rtos_task->rpc_task.service_info;
}
#endif
